//
//  MYGHealthManagementSectionHeader.swift
//  MYGrow
//
//  Created by 林矗 on 2024/3/9.
//

import UIKit
import QMUIKit

class MYGHealthManagementSectionHeader: UITableViewHeaderFooterView {
    
    var tapAddBtnBlock: (() -> Void)?
    // MARK: - Property
    var title: String = "" {
        didSet {
            label.text = title
        }
    }

    var addBtnisHidden: Bool = false {
        didSet{
            addButton.isHidden = addBtnisHidden
        }
    }

    // MARK: - init
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        backgroundColor = .white
        addSubview(label)
        label.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.left.equalTo(22.5)
            make.bottom.right.equalToSuperview()
        }
        addSubview(addButton)
        addButton.snp.makeConstraints { make in
            make.centerY.equalTo(label)
            make.right.equalToSuperview().offset(-35)
        }
    }
    
    // MARK: - Public funcs
    
    // MARK: - lazy load
    private lazy var label: UILabel = {
        let label = UILabel()
        label.font = .medium(18)
        label.textColor = .rgba(51, 51, 51)
        return label
    }()
    
    private lazy var addButton: QMUIButton = {
        let btn = QMUIButton()
        btn.setImage(UIImage(named: "Mine/tianjia"), for: .selected)
        btn.setTitle("添加", for: .normal)
        btn.setImage(UIImage(named: "Mine/tianjia"), for: .normal)
        btn.setTitleColor(.rgba(3, 3, 3, 1), for: .selected)
        btn.setTitleColor(.rgba(155, 155, 155, 1), for: .normal)
        btn.titleLabel?.font = .regular(14)
        btn.spacingBetweenImageAndTitle = 5
        btn.imagePosition = .right
        
        btn.addTarget(self, action: #selector(ClickAddButton), for: .touchUpInside)
        
        return btn
    }()
    @objc
    func ClickAddButton() {
        tapAddBtnBlock?()
    }
}
